using System;
using Csla;
using System.Collections;
namespace Manor.Business.Article
{
	[Serializable]
	public partial class Article : BusinessBase<Article>
	{

		#region Business Methods
		public static readonly PropertyInfo<int> ArtMparIdProperty = RegisterProperty<int>(c => c.ArtMparId);
		public int ArtMparId
		{
			get {return GetProperty(ArtMparIdProperty); }
			set {SetProperty(ArtMparIdProperty, value); }
		}

		public static readonly PropertyInfo<string> ArtlIdProperty = RegisterProperty<string>(c => c.ArtlId);
		public string ArtlId
		{
			get {return GetProperty(ArtlIdProperty); }
			set {SetProperty(ArtlIdProperty, value); }
		}

		public static readonly PropertyInfo<string> DescrProperty = RegisterProperty<string>(c => c.Descr);
		public string Descr
		{
			get {return GetProperty(DescrProperty); }
			set {SetProperty(DescrProperty, value); }
		}

		public static readonly PropertyInfo<string> ShortDescrProperty = RegisterProperty<string>(c => c.ShortDescr);
		public string ShortDescr
		{
			get {return GetProperty(ShortDescrProperty); }
			set {SetProperty(ShortDescrProperty, value); }
		}

		public static readonly PropertyInfo<int> MmgArtMmgIdProperty = RegisterProperty<int>(c => c.MmgArtMmgId);
		public int MmgArtMmgId
		{
			get {return GetProperty(MmgArtMmgIdProperty); }
			set {SetProperty(MmgArtMmgIdProperty, value); }
		}

		public static readonly PropertyInfo<string> SupSupIdProperty = RegisterProperty<string>(c => c.SupSupId);
		public string SupSupId
		{
			get {return GetProperty(SupSupIdProperty); }
			set {SetProperty(SupSupIdProperty, value); }
		}

		public static readonly PropertyInfo<string> PcvPcvIdPeriodeProperty = RegisterProperty<string>(c => c.PcvPcvIdPeriode);
		public string PcvPcvIdPeriode
		{
			get {return GetProperty(PcvPcvIdPeriodeProperty); }
			set {SetProperty(PcvPcvIdPeriodeProperty, value); }
		}

		public static readonly PropertyInfo<string> PcvPcvIdSaisonalProperty = RegisterProperty<string>(c => c.PcvPcvIdSaisonal);
		public string PcvPcvIdSaisonal
		{
			get {return GetProperty(PcvPcvIdSaisonalProperty); }
			set {SetProperty(PcvPcvIdSaisonalProperty, value); }
		}

		public static readonly PropertyInfo<string> PcvPcvIdBudcritProperty = RegisterProperty<string>(c => c.PcvPcvIdBudcrit);
		public string PcvPcvIdBudcrit
		{
			get {return GetProperty(PcvPcvIdBudcritProperty); }
			set {SetProperty(PcvPcvIdBudcritProperty, value); }
		}

		public static readonly PropertyInfo<DateTime> LogDelnDateProperty = RegisterProperty<DateTime>(c => c.LogDelnDate);
		public DateTime LogDelnDate
		{
			get {return GetProperty(LogDelnDateProperty); }
			set {SetProperty(LogDelnDateProperty, value); }
		}

		public static readonly PropertyInfo<string> ArtlStatusProperty = RegisterProperty<string>(c => c.ArtlStatus);
		public string ArtlStatus
		{
			get {return GetProperty(ArtlStatusProperty); }
			set {SetProperty(ArtlStatusProperty, value); }
		}

		public static readonly PropertyInfo<DateTime> InsDatProperty = RegisterProperty<DateTime>(c => c.InsDat);
		public DateTime InsDat
		{
			get {return GetProperty(InsDatProperty); }
			set {SetProperty(InsDatProperty, value); }
		}

		public static readonly PropertyInfo<string> InsOperProperty = RegisterProperty<string>(c => c.InsOper);
		public string InsOper
		{
			get {return GetProperty(InsOperProperty); }
			set {SetProperty(InsOperProperty, value); }
		}

		public static readonly PropertyInfo<DateTime> MutDatProperty = RegisterProperty<DateTime>(c => c.MutDat);
		public DateTime MutDat
		{
			get {return GetProperty(MutDatProperty); }
			set {SetProperty(MutDatProperty, value); }
		}

		public static readonly PropertyInfo<string> MutOperProperty = RegisterProperty<string>(c => c.MutOper);
		public string MutOper
		{
			get {return GetProperty(MutOperProperty); }
			set {SetProperty(MutOperProperty, value); }
		}

		public static readonly PropertyInfo<string> UomUomIdProperty = RegisterProperty<string>(c => c.UomUomId);
		public string UomUomId
		{
			get {return GetProperty(UomUomIdProperty); }
			set {SetProperty(UomUomIdProperty, value); }
		}

		public static readonly PropertyInfo<int> EtArtEtIdProperty = RegisterProperty<int>(c => c.EtArtEtId);
		public int EtArtEtId
		{
			get {return GetProperty(EtArtEtIdProperty); }
			set {SetProperty(EtArtEtIdProperty, value); }
		}

		public static readonly PropertyInfo<string> PrdRoleProperty = RegisterProperty<string>(c => c.PrdRole);
		public string PrdRole
		{
			get {return GetProperty(PrdRoleProperty); }
			set {SetProperty(PrdRoleProperty, value); }
		}

		public static readonly PropertyInfo<BusinessBase<ArticleDescription>> HasDescriptionsProperty = RegisterProperty<BusinessBase<ArticleDescription>>(c => c.HasDescriptions);
		public BusinessBase<ArticleDescription> HasDescriptions
		{
			get {return GetProperty(HasDescriptionsProperty); }
			set {SetProperty(HasDescriptionsProperty, value); }
		}

		public static readonly PropertyInfo<BusinessBindingListBase<ArticleImagesList, ArticleImages>> HasArticleImagesProperty = RegisterProperty<BusinessBindingListBase<ArticleImagesList, ArticleImages>>(c => c.HasArticleImages);
		public BusinessBindingListBase<ArticleImagesList, ArticleImages> HasArticleImages
		{
			get {return GetProperty(HasArticleImagesProperty); }
			private set {LoadProperty(HasArticleImagesProperty, value); }
		}

		protected override object GetIdValue()
		{
			return ArtMparId;
		}

		#endregion

		#region Business Rules
		protected override void AddBusinessRules()
		{
			base.AddBusinessRules();

			BusinessRules.AddRule(new Csla.Rules.CommonRules.Required(ArtMparIdProperty));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(ArtlIdProperty, 20));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.Required(ArtlIdProperty));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(DescrProperty, 40));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(ShortDescrProperty, 20));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.Required(MmgArtMmgIdProperty));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(SupSupIdProperty, 10));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(PcvPcvIdPeriodeProperty, 20));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(PcvPcvIdSaisonalProperty, 20));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(PcvPcvIdBudcritProperty, 20));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(ArtlStatusProperty, 10));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.Required(InsDatProperty));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(InsOperProperty, 15));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.Required(InsOperProperty));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(MutOperProperty, 15));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(UomUomIdProperty, 10));
			BusinessRules.AddRule(new Csla.Rules.CommonRules.MaxLength(PrdRoleProperty, 1));
		}

		#endregion

		#region Factory Methods
		internal static Article NewArticle()
		{
			var article = DataPortal.Create<Article>();
			return article;
		}

		internal static Article Get(int id)
		{
			return DataPortal.Fetch<Article>(id);
		}

		public static void Delete(int id)
		{
			DataPortal.Delete<Article>(id);
		}

		private Article()
		{
			/* Require use of factory methods */ 
		}

		#endregion

		#region Data Portal
		[RunLocal]
		protected override void DataPortal_Create()
		{
			//load default values here
			//omit this override if you have no defaults to set
			HasDescriptions = ArticleDescription.New();
			HasArticleImages = ArticleImagesList.New();
			base.DataPortal_Create();
		}

		// ReSharper disable UnusedMember.Local
		private void DataPortal_Fetch(int id)
		// ReSharper restore UnusedMember.Local
		{
			using (BypassPropertyChecks)
			{
				//Stub: Read DataBase and write it to the CSLA Object 
				//LoadProperty(ArtMparIdProperty, ???ArtMparId);
				//LoadProperty(ArtlIdProperty, ???ArtlId);
				//LoadProperty(DescrProperty, ???Descr);
				//LoadProperty(ShortDescrProperty, ???ShortDescr);
				//LoadProperty(MmgArtMmgIdProperty, ???MmgArtMmgId);
				//LoadProperty(SupSupIdProperty, ???SupSupId);
				//LoadProperty(PcvPcvIdPeriodeProperty, ???PcvPcvIdPeriode);
				//LoadProperty(PcvPcvIdSaisonalProperty, ???PcvPcvIdSaisonal);
				//LoadProperty(PcvPcvIdBudcritProperty, ???PcvPcvIdBudcrit);
				//LoadProperty(LogDelnDateProperty, ???LogDelnDate);
				//LoadProperty(ArtlStatusProperty, ???ArtlStatus);
				//LoadProperty(InsDatProperty, ???InsDat);
				//LoadProperty(InsOperProperty, ???InsOper);
				//LoadProperty(MutDatProperty, ???MutDat);
				//LoadProperty(MutOperProperty, ???MutOper);
				//LoadProperty(UomUomIdProperty, ???UomUomId);
				//LoadProperty(EtArtEtIdProperty, ???EtArtEtId);
				//LoadProperty(PrdRoleProperty, ???PrdRole);
				LoadProperty(HasDescriptionsProperty, ArticleDescription.Get(ArtMparId));
				LoadProperty(HasArticleImagesProperty, ArticleImagesList.Get(ArtMparId));
			}

		}

		 [Transactional(TransactionalTypes.TransactionScope)]
		// ReSharper disable UnusedMember.Local
		// ReSharper disable UnusedParameter.Local
		protected override void DataPortal_Insert()
		// ReSharper restore UnusedParameter.Local
		// ReSharper restore UnusedMember.Local
		{
			using (BypassPropertyChecks)
			{
				//Stub: Write Data to a new DB Object
				//dbObject.ArtMparId = ArtMparId;
				//dbObject.ArtlId = ArtlId;
				//dbObject.Descr = Descr;
				//dbObject.ShortDescr = ShortDescr;
				//dbObject.MmgArtMmgId = MmgArtMmgId;
				//dbObject.SupSupId = SupSupId;
				//dbObject.PcvPcvIdPeriode = PcvPcvIdPeriode;
				//dbObject.PcvPcvIdSaisonal = PcvPcvIdSaisonal;
				//dbObject.PcvPcvIdBudcrit = PcvPcvIdBudcrit;
				//dbObject.LogDelnDate = LogDelnDate;
				//dbObject.ArtlStatus = ArtlStatus;
				//dbObject.InsDat = InsDat;
				//dbObject.InsOper = InsOper;
				//dbObject.MutDat = MutDat;
				//dbObject.MutOper = MutOper;
				//dbObject.UomUomId = UomUomId;
				//dbObject.EtArtEtId = EtArtEtId;
				//dbObject.PrdRole = PrdRole;
				//dbObject.Save();
			}

			FieldManager.UpdateChildren(this);
		}

		// ReSharper disable UnusedMember.Local
		 [Transactional(TransactionalTypes.TransactionScope)]
		protected override void DataPortal_Update()
		// ReSharper restore UnusedMember.Local
		{
			if (IsSelfDirty)
			{
				using (BypassPropertyChecks)
				{
					//Stub: Write Data to the corresponding DB Object
					//dbObject.ArtMparId = ArtMparId;
					//dbObject.ArtlId = ArtlId;
					//dbObject.Descr = Descr;
					//dbObject.ShortDescr = ShortDescr;
					//dbObject.MmgArtMmgId = MmgArtMmgId;
					//dbObject.SupSupId = SupSupId;
					//dbObject.PcvPcvIdPeriode = PcvPcvIdPeriode;
					//dbObject.PcvPcvIdSaisonal = PcvPcvIdSaisonal;
					//dbObject.PcvPcvIdBudcrit = PcvPcvIdBudcrit;
					//dbObject.LogDelnDate = LogDelnDate;
					//dbObject.ArtlStatus = ArtlStatus;
					//dbObject.InsDat = InsDat;
					//dbObject.InsOper = InsOper;
					//dbObject.MutDat = MutDat;
					//dbObject.MutOper = MutOper;
					//dbObject.UomUomId = UomUomId;
					//dbObject.EtArtEtId = EtArtEtId;
					//dbObject.PrdRole = PrdRole;
					//dbObject.Save();
				}

			}

			FieldManager.UpdateChildren(this);
		}

		 [Transactional(TransactionalTypes.TransactionScope)]
		// ReSharper disable UnusedMember.Local
		protected override void DataPortal_DeleteSelf()
		// ReSharper restore UnusedMember.Local
		{
			DataPortal_Delete(ArtMparId);
		}

		// ReSharper disable UnusedMember.Local
		private void DataPortal_Delete(int ArtMparId)
		// ReSharper restore UnusedMember.Local
		{
			//Stub: Delete the corresponding DB Object id=ArtMparId
		}

		#endregion
	}

}

